package com.ostrich.note.ui.settings.views;

import android.view.View;

import com.blankj.utilcode.util.SPUtils;
import com.bumptech.glide.Glide;
import com.ostrich.note.R;
import com.ostrich.note.base.BaseFragment;
import com.ostrich.note.base.BaseMvvmFragment;
import com.ostrich.note.databinding.FragmentSettingsBinding;
import com.ostrich.note.entity.BaseResponseEntity;
import com.ostrich.note.ui.settings.entity.UserEntity;
import com.ostrich.note.ui.settings.viewmodel.SettingsViewModel;

import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;


public class SettingsFragment extends BaseMvvmFragment<FragmentSettingsBinding, SettingsViewModel> {


    @Override
    public int getLayout() {
        return R.layout.fragment_settings;
    }

    @Override
    public void initData() {
        viewModel.noteUserQueue().observe(this, new Observer<BaseResponseEntity<UserEntity>>() {
            @Override
            public void onChanged(BaseResponseEntity<UserEntity> userEntityBaseResponseEntity) {
                if(userEntityBaseResponseEntity.getCode() == 200){
                    binding.setUser(userEntityBaseResponseEntity.getData());
                    String avatar = userEntityBaseResponseEntity.getData().getAvatar();
                    String name = userEntityBaseResponseEntity.getData().getName();
                    SPUtils.getInstance().put("avatar",avatar);
                    SPUtils.getInstance().put("name",name);
                }
            }
        });


    }

    @Override
    public void initView() {

    }

    @Override
    public void initListener() {
        //修改资料
        binding.btnEdit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(SettingsEditActivity.class);
            }
        });
        //分类
        binding.btnType.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(SettingsTypeActivity.class);
            }
        });
        //草稿箱
        binding.btnDraft.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(SettingsDraftActivity.class);
            }
        });
        //意见反馈
        binding.btnOpinion.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(SettingsOpinionActivity.class);
            }
        });
        //收藏夹
        binding.btnCollection.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(SettingsCollectActivity.class);
            }
        });
        //用户协议
        binding.btnUser.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(SettingsProtocolActivity.class);
            }
        });

    }

    @Override
    public void createViewModel() {
        viewModel = new ViewModelProvider(this).get(SettingsViewModel.class);
    }
}